package com.atbeijing.D07;

import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * sum,max,min,maxBy
 */
public class MyExample {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Tuple3<String, Integer, Integer>> stream = env.fromElements(
                Tuple3.of("a", 9, 5),
                Tuple3.of("a", 2, 6),
                Tuple3.of("b", 3, 7),
                Tuple3.of("b", 4, 8)

        );

        //positionToSum表示元组哪个位置求和
//        stream.keyBy(r -> r.f0).sum(2).print();
//        stream.keyBy(r -> r.f0).sum("f1").print();
//        stream.keyBy(r -> r.f0).max(1).print();
//        stream.keyBy(r -> r.f0).max("f1").print();
//        stream.keyBy(r -> r.f0).min(1).print();
//        stream.keyBy(r -> r.f0).min("f1").print();
        stream.keyBy(r -> r.f0).maxBy(1).print();
//        stream.keyBy(r -> r.f0).maxBy("f1").print();
//        stream.keyBy(r -> r.f0).minBy(1).print();
//        stream.keyBy(r -> r.f0).minBy("f1").print();

        env.execute();
    }
}
